$(function(){
    function chooseCondition(id, hn){
        $("#" + id).click(function(){
            $("#" + id + "_FrameDiv").toggle();
        });
        $.each($("#" + id + "_Items .item"), function(i, o){
            $(o).hover(function(){
                $(this).addClass($(this).attr("overclass"));
            }, function(){
                $(this).removeClass($(this).attr("overclass"));
            });
			if($(hn).val()==$(this).attr("index")){
				$("#" + id + "_Display").html($(this).html());
			}
            $(o).click(function(){
                $("#" + id + "_Display").html($(this).html());
                var className = $(this).attr("selectedclass");
                $.each($("#" + id + "_Items ." + className), function(i2, o2){
                	$(o2).removeClass(className);
                });
                $(this).addClass(className);
				$(hn).val($(this).attr("index"));
            });
        });
        $(document).click(function(event){
            if ($(event.target).attr("area") != "bar") {
                $("#" + id + "_FrameDiv").hide();
            }
        });
    }
    chooseCondition("District2", "#district");
    chooseCondition("Purpose2", "#area");
    chooseCondition("Price2", "#price");
	chooseCondition("Room2", "#room");
});

